package cn.edu.wfit.modules.infomanagement.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.infomanagement.domain.College;
import cn.edu.wfit.modules.infomanagement.service.ICollegeService;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 二级学院Controller
 * 
 * @author 韩强
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/college")
public class CollegeController extends BaseController
{
    @Autowired
    private ICollegeService collegeService;

    /**
     * 查询二级学院列表
     */
    @RequiresPermissions("system:college:list")
    @GetMapping("/list")
    public TableDataInfo list(College college)
    {
        startPage();
        List<College> list = collegeService.selectCollegeList(college);
        return getDataTable(list);
    }

    /**
     * 导出二级学院列表
     */
    @RequiresPermissions("system:college:export")
    @Log(title = "二级学院", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, College college)
    {
        List<College> list = collegeService.selectCollegeList(college);
        ExcelUtil<College> util = new ExcelUtil<College>(College.class);
        util.exportExcel(response, list, "二级学院数据");
    }

    /**
     * 获取二级学院详细信息
     */
    @RequiresPermissions("system:college:query")
    @GetMapping(value = "/{collegeId}")
    public AjaxResult getInfo(@PathVariable("collegeId") Long collegeId)
    {
        return success(collegeService.selectCollegeByCollegeId(collegeId));
    }

    /**
     * 新增二级学院
     */
    @RequiresPermissions("system:college:add")
    @Log(title = "二级学院", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody College college)
    {
        return toAjax(collegeService.insertCollege(college));
    }

    /**
     * 修改二级学院
     */
    @RequiresPermissions("system:college:edit")
    @Log(title = "二级学院", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody College college)
    {
        return toAjax(collegeService.updateCollege(college));
    }

    /**
     * 删除二级学院
     */
    @RequiresPermissions("system:college:remove")
    @Log(title = "二级学院", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collegeIds}")
    public AjaxResult remove(@PathVariable Long[] collegeIds)
    {
        return toAjax(collegeService.deleteCollegeByCollegeIds(collegeIds));
    }
}
